{% extends "upload/layer_upload_base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load layer_tags %}

{% block body_class %}data data-list upload{% endblock %}

{% block title %} {% trans "Upload Layer Step: Set SRS" %} - {{ block.super }} {% endblock %}

{% block head %}
{{ block.super }}
{% endblock %}

{% block body %}
<div class="span7">
  <h2> {% trans "Provide CRS for " %} "{{ layer_name }}" </h2>

  <form method="POST" id="crsForm" role="form">
    <h3>{% trans "Coordinate Reference System" %}</h3>
    {% csrf_token %}
        {% if native_crs %}
            <p>
            {% blocktrans %}
                A coordinate reference system for this layer could not be determined.
                Locate or enter the appropriate ESPG code for this layer below.
                One way to do this is do visit:
                <a href="http://prj2epsg.org/search" target="_">prj2epsg</a>
                and enter the following:
            {% endblocktrans %}
            </p>
            <pre>
            {% if native_crs %}{{ native_crs }}{% else %}{% trans "Native CRS could not be found!" %}{% endif %}
            </pre>
        {% endif %}
        <div title="{% trans "Provide EPSG code for Source SRS" %}">
            <label for="id_source" style="display: inline-block; width: 275px">{% trans "EPSG Code (Source SRS)" %}  :</label>
            <select id="id_source" name="source" style="display: inline-block; max-width: 500px">
              <option value="">{% trans "Select a Source SRS" %}</option>
              {% for option in supported_crs %}
              <option value="{{ option }}">{{ option|crs_labels }}</option>
              {% endfor %}
            </select>
            <span class="help-tip">
                <p>{% blocktrans %}Source SRS EPSG Code is mandatory and represents the native data Spatial Reference System.
                    <br><br>
                    This must be coherent with the Geometry values (lon/lat coordinates as an instance) stored on the geospatial dataset.
                    <br><br>
                    If not specified on the geospatial data itself, it must be manually declared by the operator.
                    <br><br>
                    More information is provided at the bottom of the page in the "Additional Help" sections.
                    {% endblocktrans %}</p>
            </span>
        </div>

        <a href="{% url "layer_upload" %}" class="btn btn-primary pull-left">{% trans "Cancel" %}</a> &nbsp;
        <button id='next' class="btn btn-default" type="submit" value="{% trans 'Next' %}"> Next
            <i id="next-spinner" class="fa fa-spinner fa-spin hide"></i>
        </button>
        <div id="upload-status"></div>

        <div class="panel-group" id="accordion">
            <div class="faqHeader"><h5>{% trans "Advanced Options" %}:</h5></div>

            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title" style="font-size:16px">
                        <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse_id_target_srs">{% trans "Target SRS" %}</a>
                    </h4>
                </div>
                <div id="collapse_id_target_srs" class="panel-collapse collapse">
                    <div class="panel-body">
                        <label for="id_target" style="display: inline-block; width: 275px">{% trans "EPSG Code (Target SRS)" %}  :</label>
                        <select id="id_target" name="target" style="display: inline-block; width: 181px">
                          <option value="">{% trans "Select a Target SRS" %}</option>
                          {% for option in supported_crs %}
                          <option value="{{ option }}">{{ option|crs_labels }}</option>
                          {% endfor %}
                        </select><em><i>&nbsp;&nbsp;{% trans "leave it empty to use only Source SRS" %}</i></em>
                    </div>
                </div>

                <div class="panel-heading">
                    <h4 class="panel-title" style="font-size:16px">
                        <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse_id_help">{% trans "Additional Help" %}</a>
                    </h4>
                </div>
                <div id="collapse_id_help" class="panel-collapse collapse">
                    <div id="srshelp" class="panel-body">
                        <h4>{% trans "Spatial Reference System" %}</h4>
                        <p>{% blocktrans %}A spatial reference system (SRS) or coordinate reference system (CRS) is a coordinate-based local,
                            regional or global system used to locate geographical entities. A spatial reference system defines a specific map
                            projection, as well as transformations between different spatial reference systems. Spatial reference systems are
                            defined by the OGC's Simple feature access using well-known text, and support has been implemented by several
                            standards-based geographic information systems. Spatial reference systems can be referred to using a SRID integer,
                            including EPSG codes defined by the International Association of Oil and Gas Producers.
                            It is specified in ISO 19111:2007 Geographic information—Spatial referencing by coordinates, also published as
                            OGC Abstract Specification, Topic 2: Spatial referencing by coordinate.{% endblocktrans %}</p>
                        <h4>{% trans "Identifiers" %}</h4>
                        <p>
                        {% blocktrans %}
                        A Spatial Reference System Identifier (SRID) is a unique value used to unambiguously identify projected, unprojected,
                        and local spatial coordinate system definitions. These coordinate systems form the heart of all GIS applications.

                        Virtually all major spatial vendors have created their own SRID implementation or refer to those of an authority,
                        such as the European Petroleum Survey Group (EPSG).
                        {% endblocktrans %}
                        </p>

                        <p class="alert alert-info">{% blocktrans %}NOTE: As of 2005 the EPSG SRID values are now maintained by the International
                            Association of Oil & Gas Producers (OGP) Surveying & Positioning Committee{% endblocktrans %}</p>

                        <p>
                        {% blocktrans %}
                        SRIDs are the primary key for the Open Geospatial Consortium (OGC) spatial_ref_sys metadata table for the Simple
                        Features for SQL Specification, Versions 1.1 and 1.2, which is defined as follows:
                        {% endblocktrans %}
                        </p>
                        <pre>
    CREATE TABLE SPATIAL_REF_SYS
    (
        SRID      INTEGER   NOT NULL PRIMARY KEY,
        AUTH_NAME CHARACTER VARYING(256),
        AUTH_SRID INTEGER,
        SRTEXT    CHARACTER VARYING(2048)
    )
                        </pre>

                        <p>
                        {% blocktrans %}
                        In spatially enabled databases (such as IBM DB2, IBM Informix, Microsoft SQL Server, MySQL, Oracle RDBMS, Teradata, PostGIS and
                        SQL Anywhere), SRIDs are used to uniquely identify the coordinate systems used to define columns of spatial data or individual
                        spatial objects in a spatial column (depending on the spatial implementation). SRIDs are typically associated with a well known
                        text (WKT) string definition of the coordinate system (SRTEXT, above). From the Well Known Text Wikipedia page
                        {% endblocktrans %}
                        </p>

                        <p class="alert alert-info">{% blocktrans %}“A WKT string for a spatial reference system describes the datum, geoid, coordinate system,
                            and map projection of the spatial objects”.{% endblocktrans %}</p>

                        <p>
                        {% blocktrans %}
                        Here are two common coordinate systems with their EPSG SRID value followed by their well known text:
                        {% endblocktrans %}
                        </p>

                        <p>
                        {% blocktrans %}
                        UTM, Zone 17N, NAD27 — SRID 2029
                        {% endblocktrans %}
                        </p>

                        <pre>
    PROJCS["NAD27(76) / UTM zone 17N",
        GEOGCS["NAD27(76)",
            DATUM["North_American_Datum_1927_1976",
                SPHEROID["Clarke 1866",6378206.4,294.9786982138982,
                    AUTHORITY["EPSG","7008"]],
                AUTHORITY["EPSG","6608"]],
            PRIMEM["Greenwich",0,
                AUTHORITY["EPSG","8901"]],
            UNIT["degree",0.01745329251994328,
                AUTHORITY["EPSG","9122"]],
            AUTHORITY["EPSG","4608"]],
        UNIT["metre",1,
            AUTHORITY["EPSG","9001"]],
        PROJECTION["Transverse_Mercator"],
        PARAMETER["latitude_of_origin",0],
        PARAMETER["central_meridian",-81],
        PARAMETER["scale_factor",0.9996],
        PARAMETER["false_easting",500000],
        PARAMETER["false_northing",0],
        AUTHORITY["EPSG","2029"],
        AXIS["Easting",EAST],
        AXIS["Northing",NORTH]]
                        </pre>

                        <p>
                        {% blocktrans %}
                        WGS84 — SRID 4326
                        {% endblocktrans %}
                        </p>

                        <pre>
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.01745329251994328,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]]
                        </pre>

                        <p>
                        {% blocktrans %}
                        SRID values associated with spatial data can be used to constrain spatial operations — for instance, spatial operations cannot be performed
                        between spatial objects with differing SRIDs in some systems, or trigger coordinate system transformations between spatial objects in others.
                        {% endblocktrans %}
                        </p>

                        <h4>{% trans "EPSG Code (Source SRS)" %}</h4>
                        <p>{% blocktrans %}Source SRS EPSG Code is mandatory and represents the native data Spatial Reference System. This must be coherent with the
                            Geometry values (lon/lat coordinates as an instance) stored on the geospatial dataset. If not specified on the geospatial data itself, it
                            must be manually declared by the operator.{% endblocktrans %}</p>
                        <h4>{% trans "EPSG Code (Target SRS)" %}</h4>
                        <p>{% blocktrans %}Target SRS EPSG Code is optional. This must be used only if we need to re-project the coordinates from Source SRS to another one.
                        {% endblocktrans %}
                        </p>
                    </div>
                </div>

            </div>
        </div>
  </form>
</div>
{% endblock %}

{% block extra_script %}
{{ block.super }}
<script data-main="{% static 'geonode/js/upload/srs.js' %}"
  src="{% static 'lib/js/require.js' %}">
</script>
<script type="text/javascript">
{% autoescape off %}
{% if async_upload %}
//enableUploadProgress('timeForm');
{% endif %}
{% endautoescape %}
</script>
{% endblock %}
